package com.asset.inventory.network

import com.asset.inventory.model.*
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import io.reactivex.Observable
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory


/**
 *    @author : sibb
 *    date   : 21-4-7
 *    desc   : http 工具类
 */
class HttpUtils private constructor() {

    private  var request: Request
    init {
        val retrofit = Retrofit.Builder().baseUrl(Request.BASE_URL)
            .client(OkHttpConfig.getOkHttpClient())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build()
         request = retrofit.create(Request::class.java)
    }
    companion object {
        val instance: HttpUtils by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            HttpUtils() }
    }


    //登录
    fun login(body: LoginRequest): Observable<Response> {
        return request.login(body)
    }

    //获取任务列表
    fun getTaskList(): Observable<TaskBean> = request.getTaskList()

    //获取任务详情
    fun getTaskDetail(id: Long): Observable<TaskDetailBean> = request.getTaskDetail(id)

    //修改资产属性
    fun putAssetsField(id: Long, assetField: TaskDetailBean.Detail): Observable<ModifyAssetsModel> = request.putAssetsField(id,assetField)

    //获取部门人员数据
    fun getOrgList(): Observable<OrgModel> = request.getOrgList()

    //获取可用位置列表
    fun getEnableLoctionList(): Observable<LocationModel> = request.getEnableLoctionList()

    //修改盘点状态
    fun putState(id: Long, state: String): Observable<Response> = request.putState(id,state)

    //提交任务
    fun commit(id: Long): Observable<ModifyAssetsModel> = request.commit(id)

    //批量盘平
    fun commitList(ids: List<Long>): Observable<ModifyAssetsModel> = request.commitList(ids)




}